package seatiger.tomcat.catalina.core;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import java.util.Enumeration;

/**
 * 对StandardWrapper的门面
 */
public class StandardWrapperFacade<T extends ServletConfig> implements ServletConfig {

    private T config;

    public StandardWrapperFacade(T config){
        this.config = config;
    }

    @Override
    public String getServletName() {
        return config.getServletName();
    }

    @Override
    public ServletContext getServletContext() {
        ServletContext context = config.getServletContext();
        if (context != null && context instanceof ApplicationContext){
            return ((ApplicationContext) context).getFacade();
        }
        return context;
    }

    @Override
    public String getInitParameter(String name) {
        return config.getInitParameter(name);
    }

    @Override
    public Enumeration getInitParameterNames() {
        return config.getInitParameterNames();
    }
}
